package com.lh0811.forge.pserv.uacs.server.component.data_scope;

import com.lh0811.forge.pserv.uacs.api.component.data_scope.DataScopeHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DataScopeHandlerImpl implements DataScopeHandler {

    private static final ThreadLocal<Boolean> threadLocal = new ThreadLocal<>();

    @Override
    public <Resp> Resp delegateQuerySql(Callback<Resp> callback) {
        threadLocal.set(Boolean.TRUE);
        // 记录需要数据限制
        Resp execute = callback.execute();
        threadLocal.remove();
        return execute;
    }

    public static Boolean getDataScopeFlag() {
        return BooleanUtils.isTrue(threadLocal.get());
    }
}
